<!DOCTYPE html>
<html lang=en>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="Dapper-Extensions Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dappe">
<meta property="og:type" content="article">
<meta property="og:title" content="Dapper-Extensions官方文档中文版">
<meta property="og:url" content="http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/index.html">
<meta property="og:site_name" content="TmoonSite">
<meta property="og:description" content="Dapper-Extensions Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dappe">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2017-01-23T01:30:51.000Z">
<meta property="article:modified_time" content="2020-01-07T10:48:14.863Z">
<meta property="article:author" content="Tmoonlight">
<meta name="twitter:card" content="summary">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/logo2.gif" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/logo2.gif">
          
        
    
    <!-- title -->
    <title>Dapper-Extensions官方文档中文版</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
<meta name="generator" content="Hexo 4.2.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Writing</a></li>
         
          <li><a href="/projects_url">Projects</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2017/02/03/ASP.NET%E4%B8%AD%E5%85%B3%E4%BA%8EAsync%E5%92%8CAwait%E7%9A%84%E6%A6%82%E8%BF%B0/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2017/01/21/Dapper%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86%E6%95%B4%E7%90%86/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">Share post</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&text=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&is_video=false&description=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=Dapper-Extensions官方文档中文版&body=Check out this article: http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&name=Dapper-Extensions官方文档中文版&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&t=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Dapper-Extensions"><span class="toc-number">1.</span> <span class="toc-text">Dapper-Extensions</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Introduction"><span class="toc-number">1.1.</span> <span class="toc-text">Introduction</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Features"><span class="toc-number">1.2.</span> <span class="toc-text">Features</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Naming-Conventions-命名约定"><span class="toc-number">1.3.</span> <span class="toc-text">Naming Conventions(命名约定)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Installation"><span class="toc-number">1.4.</span> <span class="toc-text">Installation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Examples"><span class="toc-number">1.5.</span> <span class="toc-text">Examples</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Get-Operation"><span class="toc-number">1.6.</span> <span class="toc-text">Get Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Simple-Insert-Operation"><span class="toc-number">1.7.</span> <span class="toc-text">Simple Insert Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Advanced-Insert-Operation-Composite-Key-复合主键"><span class="toc-number">1.8.</span> <span class="toc-text">Advanced Insert Operation (Composite Key)复合主键</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Simple-Update-Operation"><span class="toc-number">1.9.</span> <span class="toc-text">Simple Update Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Simple-Delete-Operation"><span class="toc-number">1.10.</span> <span class="toc-text">Simple Delete Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#GetList-Operation-with-Predicates"><span class="toc-number">1.11.</span> <span class="toc-text">GetList Operation (with Predicates)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Count-Operation-with-Predicates"><span class="toc-number">1.12.</span> <span class="toc-text">Count Operation (with Predicates)</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#AutoClassMapper"><span class="toc-number"></span> <span class="toc-text">AutoClassMapper</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#AutoClassMapper-Assumptions"><span class="toc-number">1.</span> <span class="toc-text">AutoClassMapper Assumptions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Customized-PluralizedAutoClassMapper"><span class="toc-number">2.</span> <span class="toc-text">Customized PluralizedAutoClassMapper</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#KeyTypes"><span class="toc-number"></span> <span class="toc-text">KeyTypes</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#NotAKey"><span class="toc-number">1.</span> <span class="toc-text">NotAKey</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Identity"><span class="toc-number">2.</span> <span class="toc-text">Identity</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Guid"><span class="toc-number">3.</span> <span class="toc-text">Guid</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Assigned"><span class="toc-number">4.</span> <span class="toc-text">Assigned</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Predicates"><span class="toc-number"></span> <span class="toc-text">Predicates</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Simple-FieldPredicate-Operation"><span class="toc-number">1.</span> <span class="toc-text">Simple FieldPredicate Operation</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Compound-Predicate-Predicate-Group-复合谓词"><span class="toc-number">2.</span> <span class="toc-text">Compound Predicate (Predicate Group)复合谓词</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Multiple-Compound-Predicates-Predicate-Group"><span class="toc-number">3.</span> <span class="toc-text">Multiple Compound Predicates (Predicate Group)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PropertyPredicate"><span class="toc-number">4.</span> <span class="toc-text">PropertyPredicate</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Exists-Predicate"><span class="toc-number">5.</span> <span class="toc-text">Exists Predicate</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        Dapper-Extensions官方文档中文版
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">TmoonSite</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2017-01-23T01:30:51.000Z" itemprop="datePublished">2017-01-23</time>
        
      
    </div>


      

      

    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h2 id="Dapper-Extensions"><a href="#Dapper-Extensions" class="headerlink" title="Dapper-Extensions"></a>Dapper-Extensions</h2><blockquote>
<p>Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.</p>
</blockquote>
<p><a href="https://github.com/tmsmith/Dapper-Extensions" target="_blank" rel="noopener" title="github：https://github.com/tmsmith/Dapper-Extensions">github：https://github.com/tmsmith/Dapper-Extensions</a></p>
<ul>
<li>Dapper是一个开源轻的量级的orm，他的优点和用法在<a href="http://www.cnblogs.com/Sinte-Beuve/p/4231053.html" target="_blank" rel="noopener">之前写的博客</a>中有提到。可是它只支持带sql语句的CRUD。</li>
<li>Dapper-Extensions也是一个开源库，他在Dapper的基础上封装了基本的CRUD操作，使得一些简单的数据库操作可以不用自己写sql语句。使用起来更方面。</li>
</ul>
<h3 id="Introduction"><a href="#Introduction" class="headerlink" title="Introduction"></a>Introduction</h3><p>Dapper Extensions是github上的一个开源库是对StackOVerflow开发的Dapper ORM的一个扩展。它增加了基础的CRUD操作（(Get, Insert, Update, Delete)），对更高级的查询场景，该类库还提供了一套谓词系统。它的目标是保持POCOs的纯净，不需要额外的attributes和类的继承。</p>
<p>自定义映射请参见 <a href="http://www.cnblogs.com/Sinte-Beuve/p/4612971.html" target="_blank" rel="noopener">ClassMapper</a></p>
<h3 id="Features"><a href="#Features" class="headerlink" title="Features"></a>Features</h3><ul>
<li>零配置</li>
<li>自动映射POCOs的CRUD操作</li>
<li>GetList, Count等方法可以用于更高级的场景。</li>
<li>GetPage for returning paged result sets.支持分页</li>
<li>自动支持Guid和Integer类型的主键，（也可以手动指定其他键类型）</li>
<li>通过使用ClassMapper可以使保证POCOs纯净。 (Attribute Free!)</li>
<li>可以通过使用ClassMapper来自定义entity-table映射</li>
<li>支持联合主键</li>
<li>POCO类名默认与数据表名相匹配，也可以自定义</li>
<li>易于使用的 <a href="https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates" target="_blank" rel="noopener">Predicate System</a>适用于高级场合</li>
<li>在生成SQL语句时正确转义表名和类名 (Ex: SELECT FirstName FROM Users WHERE Users.UserId = @ UserId_0）</li>
<li>覆盖单元测试（覆盖了150+个单元测试）</li>
</ul>
<h3 id="Naming-Conventions-命名约定"><a href="#Naming-Conventions-命名约定" class="headerlink" title="Naming Conventions(命名约定)"></a>Naming Conventions(命名约定)</h3><ul>
<li>POCO类名与数据库中表名匹配，多元化（Pluralized）的表名（暂时理解为别名吧）可以通过PlurizedAutoClassMapper来自定义。</li>
<li>POCO类中属性名和数据库表中的类名匹配。</li>
<li>暂约定主键被命名为Id.使用其他主键需要自定义映射（ClassMapper）。</li>
</ul>
<h3 id="Installation"><a href="#Installation" class="headerlink" title="Installation"></a>Installation</h3><p>Nuget:</p>
<p><a href="http://nuget.org/List/Packages/DapperExtensions" target="_blank" rel="noopener">http://nuget.org/List/Packages/DapperExtensions</a></p>
<p>PM&gt; Install-Package DapperExtensions</p>
<h3 id="Examples"><a href="#Examples" class="headerlink" title="Examples"></a>Examples</h3><p>pernson POCO的定义</p>
<p>public class Person</p>
<p>{</p>
<p>public int Id { get; set; }</p>
<p>public string FirstName { get; set; }</p>
<p>public string LastName { get; set; }</p>
<p>public bool Active { get; set; }</p>
<p>public DateTime DateCreated { get; set; }</p>
<p>}</p>
<h3 id="Get-Operation"><a href="#Get-Operation" class="headerlink" title="Get Operation"></a>Get Operation</h3><p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>int personId = 1;</p>
<p>Person person = cn.Get<Person>(personId);</p>
<p>cn.Close();</p>
<p>}</p>
<h3 id="Simple-Insert-Operation"><a href="#Simple-Insert-Operation" class="headerlink" title="Simple Insert Operation"></a>Simple Insert Operation</h3><p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>Person person = new Person { FirstName = “Foo”, LastName = “Bar” };</p>
<p>int id = cn.Insert(person);</p>
<p>cn.Close();</p>
<p>}</p>
<h3 id="Advanced-Insert-Operation-Composite-Key-复合主键"><a href="#Advanced-Insert-Operation-Composite-Key-复合主键" class="headerlink" title="Advanced Insert Operation (Composite Key)复合主键"></a>Advanced Insert Operation (Composite Key)复合主键</h3><p>//返回dynamic类型，若主键为单，返回主键值，若主键为复合的，返回IDictionary&lt;string,object&gt;</p>
<p>public static dynamic Insert<T>(this IDbConnection connection, T entity, IDbTransaction transaction = null, int? commandTimeout = null) where T : class</p>
<p>public class Car</p>
<p>{</p>
<p>public int ModelId { get; set; }</p>
<p>public int Year { get; set; }</p>
<p>public string Color { get; set; }</p>
<p>}</p>
<p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>Car car = new Car { Color = “Red” };</p>
<p>//返回o</p>
<p>var multiKey = cn.Insert(car);</p>
<p>cn.Close();</p>
<p>int modelId = multiKey.ModelId;</p>
<p>int year = multiKey.Year;</p>
<p>}</p>
<h3 id="Simple-Update-Operation"><a href="#Simple-Update-Operation" class="headerlink" title="Simple Update Operation"></a>Simple Update Operation</h3><p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>int personId = 1;</p>
<p>Person person = _connection.Get<Person>(personId);</p>
<p>person.LastName = “Baz”;</p>
<p>cn.Update(person);</p>
<p>cn.Close();</p>
<p>}</p>
<h3 id="Simple-Delete-Operation"><a href="#Simple-Delete-Operation" class="headerlink" title="Simple Delete Operation"></a>Simple Delete Operation</h3><p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>Person person = _connection.Get<Person>(1);</p>
<p>cn.Delete(person);</p>
<p>cn.Close();</p>
<p>}</p>
<h3 id="GetList-Operation-with-Predicates"><a href="#GetList-Operation-with-Predicates" class="headerlink" title="GetList Operation (with Predicates)"></a>GetList Operation (with Predicates)</h3><p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>var predicate = Predicates.Field<Person>(f =&gt; f.Active, Operator.Eq, true);</p>
<p>IEnumerable<Person> list = cn.GetList<Person>(predicate);</p>
<p>cn.Close();</p>
<p>}</p>
<p>Generated SQL</p>
<p>SELECT</p>
<p>[Person].[Id]</p>
<p>, [Person].[FirstName]</p>
<p>, [Person].[LastName]</p>
<p>, [Person].[Active]</p>
<p>, [Person].[DateCreated]</p>
<p>FROM [Person]</p>
<p>WHERE ([Person].[Active] = @Active_0)</p>
<h3 id="Count-Operation-with-Predicates"><a href="#Count-Operation-with-Predicates" class="headerlink" title="Count Operation (with Predicates)"></a>Count Operation (with Predicates)</h3><p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>var predicate = Predicates.Field<Person>(f =&gt; f.DateCreated, Operator.Lt, DateTime.UtcNow.AddDays(-5));</p>
<p>int count = cn.Count<Person>(predicate);</p>
<p>cn.Close();</p>
<p>}</p>
<p>Generated SQL</p>
<p>SELECT</p>
<p>COUNT(*) Total</p>
<p>FROM [Person]</p>
<p>WHERE ([Person].[DateCreated] &lt; @DateCreated_0)</p>
<p>之前翻译了Dapper-Extensions项目首页的readme.md，大家应该对这个类库的使用有一些了解了吧，接下来是wiki的文档翻译，主要提到了AutoClassMapper、KeyTypes、Predicates System的高级用法用法。</p>
<p>若不熟悉Dapper及Dapper-Extensions的，请移步：</p>
<ul>
<li><a href="http://www.cnblogs.com/Sinte-Beuve/p/4231053.html" target="_blank" rel="noopener">《Dapper的基本使用》:http://www.cnblogs.com/Sinte-Beuve/p/4231053.html</a></li>
<li><a href="http://www.cnblogs.com/Sinte-Beuve/p/4612971.html" target="_blank" rel="noopener">《Stackoverflow/dapper的Dapper-Extensions用法（一）》:http://www.cnblogs.com/Sinte-Beuve/p/4612971.html</a></li>
<li><a href="http://www.cnblogs.com/Sinte-Beuve/p/4230943.html" target="_blank" rel="noopener">(扩展)《利用Dapper ORM搭建三层架构》:http://www.cnblogs.com/Sinte-Beuve/p/4230943.html</a></li>
</ul>
<h1 id="AutoClassMapper"><a href="#AutoClassMapper" class="headerlink" title="AutoClassMapper"></a><a href="https://github.com/tmsmith/Dapper-Extensions/wiki/AutoClassMapper" target="_blank" rel="noopener">AutoClassMapper</a></h1><p>在不确定的情况下Dapper Extensions使用一个默认的ClassMapper(AutoClassMapper)来处理POCO和数据表之间的映射。ClassMapper非常重要，它可以保证POCOs的纯净，不需要增加额外的attribute。你可以通过继承ClassMapper来自定义自己的映射规则去改变Dapper Extensions的行为。(这边我觉得文档有些问题，应该是继承AutoClassMapper，因为DefaultMapper是用来设置全局的映射器的而不是单表的自定义。)</p>
<p>DapperExtensions.DapperExtensions.DefaultMapper = typeof(MyCustomClassMapper&lt;&gt;);</p>
<h2 id="AutoClassMapper-Assumptions"><a href="#AutoClassMapper-Assumptions" class="headerlink" title="AutoClassMapper Assumptions"></a>AutoClassMapper Assumptions</h2><p>默认的AutoClassMapper是建立在数据库与POCOs之间有一定约束的条件下才可以工作的。</p>
<p>约定条件如下：</p>
<ul>
<li>AutoClassMapper假定数据表名与POCOs名一致(Ex: Car table name and Car POCO name).。</li>
<li>每个POCOs必须包含一个属性名为Id或以Id结尾的。</li>
<li>如果有多个属性以Id结尾，Dapper Extensions会使用第一个”Id”属性作为主键。</li>
<li>如果Id属性的类型为整形，则它的 <a href="https://github.com/tmsmith/Dapper-Extensions/wiki/KeyTypes" target="_blank" rel="noopener">KeyType</a>属性会被设成Identity。</li>
<li>如果Id属性的类型为GUID，则它的 <a href="https://github.com/tmsmith/Dapper-Extensions/wiki/KeyTypes" target="_blank" rel="noopener">KeyType</a>属性会被设成GUID。</li>
<li>如果Id属性的类型为其他类型，则它的 <a href="https://github.com/tmsmith/Dapper-Extensions/wiki/KeyTypes" target="_blank" rel="noopener">KeyType</a>属性会被设成Assigned。（此类型为用户自定义主键）。</li>
</ul>
<h2 id="Customized-PluralizedAutoClassMapper"><a href="#Customized-PluralizedAutoClassMapper" class="headerlink" title="Customized PluralizedAutoClassMapper"></a>Customized PluralizedAutoClassMapper</h2><p>英语有很多多元化（pluralization）的规则，PluralizedAutoClassMapper会提供给我们一些正确的多元化命名为任何可能的场景。但是仍然有很多情况，当你的数据库表名和默认的Dapper Extensions的多元化规则不相匹配时，你可以自定义该类，注入自己的规则。</p>
<p>通俗的话来讲，就是说数据库表名和POCOs的命名可能会因为英文语义或者说文化等的影响而不同，这时候Dapper Extensions提供给我们PluralizedAutoClassMapper，提供一些转换的规则。例如Person和Person。</p>
<p>下面的例子，使用CustomPluralizedMapper对来Person到Persons数据表进行映射。如果不重写，PluralizedAutoClassMapper默认会把Person映射到People表。</p>
<p>public class CustomPluralizedMapper<T> : PluralizedAutoClassMapper<T> where T : class</p>
<p>{</p>
<p>protected override void Table(string tableName)</p>
<p>{</p>
<p>if(tableName.Equals(“Person”, StringComparison.CurrentCultureIgnoreCase))</p>
<p>{</p>
<p>TableName = “Persons”;</p>
<p>}</p>
<p>base.Table(tableName);</p>
<p>}</p>
<p>}</p>
<p>全局配置：</p>
<p>DapperExtensions.DapperExtensions.DefaultMapper = typeof(CustomPluralizedMapper&lt;&gt;);</p>
<h1 id="KeyTypes"><a href="#KeyTypes" class="headerlink" title="KeyTypes"></a><a href="https://github.com/tmsmith/Dapper-Extensions/wiki/KeyTypes" target="_blank" rel="noopener">KeyTypes</a></h1><p>KeyType这个enum允许Dapper Extensions知道如何去映射POCOs的主键。当你的POCOs被Dapper Extensions检查后，映射关系将被建立和缓存下下来。这个类型映射用于生产合适的SQL语句来进行子查询的调用。举个例子，在不确定的情况下，Dapper-Extensions必须知道哪一个属性是POCOs的标识。</p>
<p>下列KeyTypes是可用的：</p>
<p>public enum KeyType{</p>
<p>NotAKey,</p>
<p>Identity,</p>
<p>Guid,</p>
<p>Assigned</p>
<p>}</p>
<h2 id="NotAKey"><a href="#NotAKey" class="headerlink" title="NotAKey"></a>NotAKey</h2><p>非主键属性映射到该枚举值。</p>
<h2 id="Identity"><a href="#Identity" class="headerlink" title="Identity"></a>Identity</h2><p>任何整形的主键将被映射成这个枚举值。</p>
<h2 id="Guid"><a href="#Guid" class="headerlink" title="Guid"></a>Guid</h2><p>Guid类型的主键属性被映射成这个枚举值。这个标识会使得Dapper Extensions在数据库执行插入命令前先生成一个新的Guid值。Dapper-Extensions生成<a href="http://davybrion.com/blog/2009/05/using-the-guidcomb-identifier-strategy/" target="_blank" rel="noopener">COMB</a>(see: GetNextGuid)</p>
<h2 id="Assigned"><a href="#Assigned" class="headerlink" title="Assigned"></a>Assigned</h2><p>任意非Guid和整形的主键将会映射到该枚举值。这个标识会使得Dapper Extensions在数据库执行插入命令前不会生成一个key。再者，Dapper-Extensions在插入后不会获得任意一个键的值，总而言之，这个是由开发者决定的。即自定义主键值或者是联合主键时的标识。</p>
<h1 id="Predicates"><a href="#Predicates" class="headerlink" title="Predicates"></a><a href="https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates" target="_blank" rel="noopener">Predicates</a></h1><p>谓词系统在Dapper-Extensions中是非常容易去使用的。现在我们使用下面这个Model来展开它的用法。</p>
<p>public class Person</p>
<p>{</p>
<p>public int Id { get; set; }</p>
<p>public string FirstName { get; set; }</p>
<p>public string LastName { get; set; }</p>
<p>public bool Active { get; set; }</p>
<p>public DateTime DateCreated { get; set; }</p>
<p>}</p>
<h2 id="Simple-FieldPredicate-Operation"><a href="#Simple-FieldPredicate-Operation" class="headerlink" title="Simple FieldPredicate Operation"></a>Simple FieldPredicate Operation</h2><p>为了创建一个简单的谓词，我们仅仅创建一个字段谓词并且把它传给查询操作。FieldPredicate需要一个一般的类型，允许使用强类型。</p>
<p>下面的已给例子，我们返回Active值为true的所有Persons。</p>
<p>Code</p>
<p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>var predicate = Predicates.Field<Person>(f =&gt; f.Active, Operator.Eq, true);</p>
<p>IEnumerable<Person> list = cn.GetList<Person>(predicate);</p>
<p>cn.Close();</p>
<p>}</p>
<p>Generated SQL</p>
<p>SELECT</p>
<p>[Person].[Id]</p>
<p>, [Person].[FirstName]</p>
<p>, [Person].[LastName]</p>
<p>, [Person].[Active]</p>
<p>, [Person].[DateCreated]</p>
<p>FROM [Person]</p>
<p>WHERE ([Person].[Active] = @Active_0)</p>
<p>IN Clause TODO: Demonstrate that you can pass an IEnumerable as the value to acheive WHERE x IN (‘a’,’b’) functionality</p>
<h2 id="Compound-Predicate-Predicate-Group-复合谓词"><a href="#Compound-Predicate-Predicate-Group-复合谓词" class="headerlink" title="Compound Predicate (Predicate Group)复合谓词"></a>Compound Predicate (Predicate Group)复合谓词</h2><p>复合谓词谓词可以通过谓词组来实现。对于每个谓词组，你必须选择一个操作符（AND/OR），每个被添加到组中的谓词将会被加入具体的操作。</p>
<p>如果每个谓词组都实现了IPredicate，那么多谓词可以被同时添加到一起。</p>
<p>下面的例子，我们建立一个通过AND操作符连接的谓词组。</p>
<p>Code</p>
<p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>var pg = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };</p>
<p>pg.Predicates.Add(Predicates.Field<Person>(f =&gt; f.Active, Operator.Eq, true));</p>
<p>pg.Predicates.Add(Predicates.Field<Person>(f =&gt; f.LastName, Operator.Like, “Br%”));</p>
<p>IEnumerable<Person> list = cn.GetList<Person>(pg);</p>
<p>cn.Close();</p>
<p>}</p>
<p>Generated SQL</p>
<p>SELECT</p>
<p>[Person].[Id]</p>
<p>, [Person].[FirstName]</p>
<p>, [Person].[LastName]</p>
<p>, [Person].[Active]</p>
<p>, [Person].[DateCreated]</p>
<p>FROM [Person]</p>
<p>WHERE (([Person].[Active] = @Active_0)</p>
<p>AND ([Person].[LastName] LIKE @LastName_1))</p>
<h2 id="Multiple-Compound-Predicates-Predicate-Group"><a href="#Multiple-Compound-Predicates-Predicate-Group" class="headerlink" title="Multiple Compound Predicates (Predicate Group)"></a>Multiple Compound Predicates (Predicate Group)</h2><p>只要每个谓词组都实现了IPredicate，你可以创建复杂的复合谓词，并把它们联合起来。</p>
<p>在下面的例子中，我们创建两个谓词组，并且把它们组合在第三个谓词组中。</p>
<p>Code</p>
<p>using (SqlConnection cn = new SqlConnection(_connectionString))</p>
<p>{</p>
<p>cn.Open();</p>
<p>var pgMain = new PredicateGroup { Operator = GroupOperator.Or, Predicates = new List<IPredicate>() };</p>
<p>var pga = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };</p>
<p>pga.Predicates.Add(Predicates.Field<Person>(f =&gt; f.Active, Operator.Eq, true));</p>
<p>pga.Predicates.Add(Predicates.Field<Person>(f =&gt; f.LastName, Operator.Like, “Br%”));</p>
<p>pgMain.Predicates.Add(pga);</p>
<p>var pgb = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };</p>
<p>pgb.Predicates.Add(Predicates.Field<Person>(f =&gt; f.Active, Operator.Eq, false));</p>
<p>pgb.Predicates.Add(Predicates.Field<Person>(f =&gt; f.FirstName, Operator.Like, “Pa%”, true /* NOT */ ));</p>
<p>pgMain.Predicates.Add(pgb);</p>
<p>IEnumerable<Person> list = cn.GetList<Person>(pgMain);</p>
<p>cn.Close();</p>
<p>}</p>
<p>Generated SQL</p>
<p>SELECT</p>
<p>[Person].[Id]</p>
<p>, [Person].[FirstName]</p>
<p>, [Person].[LastName]</p>
<p>, [Person].[Active]</p>
<p>, [Person].[DateCreated]</p>
<p>FROM [Person]</p>
<p>WHERE</p>
<p>((([Person].[Active] = @Active_0) AND ([Person].[LastName] LIKE @LastName_1))</p>
<p>OR (([Person].[Active] = @Active_2) AND ([Person].[FirstName] NOT LIKE @FirstName_3)))</p>
<h2 id="PropertyPredicate"><a href="#PropertyPredicate" class="headerlink" title="PropertyPredicate"></a>PropertyPredicate</h2><p>TODO</p>
<h2 id="Exists-Predicate"><a href="#Exists-Predicate" class="headerlink" title="Exists Predicate"></a>Exists Predicate</h2><p>var subPred = Predicates.Field<User>(u =&gt; u.Email, Operator.Eq, “<a href="mailto:someone@somewhere.com">someone@somewhere.com</a>“);</p>
<p>var existsPred = Predicates.Exists<User>(subPred);</p>
<p>var existingUser = cn.GetList<User>(existsPred , null, tran).FirstOrDefault();</p>
<p>以上就是Dapper-Extensions所有的文档了。</p>

  </div>
</article>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Writing</a></li>
         
          <li><a href="/projects_url">Projects</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Dapper-Extensions"><span class="toc-number">1.</span> <span class="toc-text">Dapper-Extensions</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Introduction"><span class="toc-number">1.1.</span> <span class="toc-text">Introduction</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Features"><span class="toc-number">1.2.</span> <span class="toc-text">Features</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Naming-Conventions-命名约定"><span class="toc-number">1.3.</span> <span class="toc-text">Naming Conventions(命名约定)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Installation"><span class="toc-number">1.4.</span> <span class="toc-text">Installation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Examples"><span class="toc-number">1.5.</span> <span class="toc-text">Examples</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Get-Operation"><span class="toc-number">1.6.</span> <span class="toc-text">Get Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Simple-Insert-Operation"><span class="toc-number">1.7.</span> <span class="toc-text">Simple Insert Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Advanced-Insert-Operation-Composite-Key-复合主键"><span class="toc-number">1.8.</span> <span class="toc-text">Advanced Insert Operation (Composite Key)复合主键</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Simple-Update-Operation"><span class="toc-number">1.9.</span> <span class="toc-text">Simple Update Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Simple-Delete-Operation"><span class="toc-number">1.10.</span> <span class="toc-text">Simple Delete Operation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#GetList-Operation-with-Predicates"><span class="toc-number">1.11.</span> <span class="toc-text">GetList Operation (with Predicates)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Count-Operation-with-Predicates"><span class="toc-number">1.12.</span> <span class="toc-text">Count Operation (with Predicates)</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#AutoClassMapper"><span class="toc-number"></span> <span class="toc-text">AutoClassMapper</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#AutoClassMapper-Assumptions"><span class="toc-number">1.</span> <span class="toc-text">AutoClassMapper Assumptions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Customized-PluralizedAutoClassMapper"><span class="toc-number">2.</span> <span class="toc-text">Customized PluralizedAutoClassMapper</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#KeyTypes"><span class="toc-number"></span> <span class="toc-text">KeyTypes</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#NotAKey"><span class="toc-number">1.</span> <span class="toc-text">NotAKey</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Identity"><span class="toc-number">2.</span> <span class="toc-text">Identity</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Guid"><span class="toc-number">3.</span> <span class="toc-text">Guid</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Assigned"><span class="toc-number">4.</span> <span class="toc-text">Assigned</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Predicates"><span class="toc-number"></span> <span class="toc-text">Predicates</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Simple-FieldPredicate-Operation"><span class="toc-number">1.</span> <span class="toc-text">Simple FieldPredicate Operation</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Compound-Predicate-Predicate-Group-复合谓词"><span class="toc-number">2.</span> <span class="toc-text">Compound Predicate (Predicate Group)复合谓词</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Multiple-Compound-Predicates-Predicate-Group"><span class="toc-number">3.</span> <span class="toc-text">Multiple Compound Predicates (Predicate Group)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PropertyPredicate"><span class="toc-number">4.</span> <span class="toc-text">PropertyPredicate</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Exists-Predicate"><span class="toc-number">5.</span> <span class="toc-text">Exists Predicate</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&text=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&is_video=false&description=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=Dapper-Extensions官方文档中文版&body=Check out this article: http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&title=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&name=Dapper-Extensions官方文档中文版&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2017/01/23/Dapper-Extensions%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E4%B8%AD%E6%96%87%E7%89%88/&t=Dapper-Extensions官方文档中文版" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Tmoonlight
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Writing</a></li>
         
          <li><a href="/projects_url">Projects</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

<!-- Disqus Comments -->


</body>
</html>
